package com.blkkj.huan.Controller;


import com.aliyuncs.iot.model.v20170420.CreateProductRequest;
import com.aliyuncs.iot.model.v20170420.CreateProductResponse;
import com.blkkj.huan.util.BaseTest;
import com.blkkj.huan.util.LogUtil;
import com.blkkj.huan.util.ServiceUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CreateProductController extends BaseTest {

    @PostMapping("/CreateProduct")
    public String CreateProduct(String productName, String productDesc){
        //创建产品
        String productKey = createProductTest(productName,productDesc);

        return "huan";
    }
    /**
     * 创建产品
     *
     * @param productName 产品名称
     * @param productDesc 产品描述 可空
     * @return 产品的PK
     */
    public static String createProductTest(String productName, String productDesc) {
        CreateProductRequest request = new CreateProductRequest();
        request.setName(productName);
        request.setDesc(productDesc);
        CreateProductResponse response = (CreateProductResponse)executeTest(request);
        if (response != null && response.getSuccess() != false) {
            LogUtil.print("创建产品成功！productKey:" + response.getProductInfo().getProductKey());
            return response.getProductInfo().getProductKey();
        } else {
            LogUtil.error("创建产品失败！requestId:" + response.getRequestId() + "原因:" + response.getErrorMessage());
        }
        return null;
    }    }





